
function getNowFormatDate(){
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds();
    return currentdate;
} 
$(document).ready(
function(){ 
$("form").submit(
		function(){
			for(var k=1;k<=localStorage.length;k++)
		   {
			   if(localStorage.getItem(k)!=null)
			   {var user1=localStorage.getItem(k);
			   var user=JSON.parse(user1);
			   if((user.username!=null)&&(user.username==document.getElementById("user_text").value))
			   {if(user.password1==$("#user_password").val())
				   {var date=getNowFormatDate();
			        user.logtime=date;
					user=JSON.stringify(user);
					localStorage.setItem(k,user);
					localStorage.setItem("state",document.getElementById("user_text").value);
				   window.location.href="../success/success.html";
                    return false;
					window.event.returnValue = false;
				   }
				else
				{ $("p").eq(3).html("wrong password!");
			      $("p").eq(3).css({"font-size":"15px","color":"red"});
				return false;
			       
				   }
		       }
		  }
              else continue;		   
		   }	
		   $("p").eq(1).html("username don't exist!");
			      $("p").eq(1).css({"font-size":"15px","color":"red"});
				  return false;
		  
		   });
	
	

$("input").focus(
 function(){$("p").eq(3).html("");
$("p").eq(1).html("");})})
	 // function correct(form)
	 // {
	       // for(var k=0;k<parseInt(localStorage.length/5);k++)
		   // {if(localStorage.getItem(k+1)!=document.getElementById("user_text").value)
		      // continue;
		      // else 
			  // if(localStorage.getItem("password"+(k+1))==document.getElementById("user_password").value)
			  // {alert("success!");
			  // var data2=getNowFormatDate();
			  // localStorage.setItem(document.getElementById("user_text").value+"_log_time",data2);
			  // localStorage.setItem("now",document.getElementById("user_text").value);
			  // window.location.href='../success/success.html';
			  // window.event.returnValue = false;
			  
              // return true;}
			  // else 
			  // {alert("wrong password!");
			  // return false;}}
			  // alert("your username don't exist!");	   
	 // }